<%--
  Created by IntelliJ IDEA.
  User: zbx20
  Date: 2023/8/27
  Time: 21:26
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
    <title>Title</title>
</head>
<script src="jQuery-3.3.1min.js"></script>
<script>
    $(function () {
        let params = new URLSearchParams(location.search);
        let page = params.get("page");
        if (page == null||page<1) {
            page = 1;
        }
        let size = params.get("size");
        if (size == null) {
            size = 2;
        }

        $.post("users", {action: "list", "page": page, "size": size}, function (data) {
            let json = $.parseJSON(data);
            json.forEach(function (zhi) {
                $("#tab").append(" <tr> " +
                    "<td>" + zhi.hotel_id+ "</td>"+
                    "<td>" + zhi.name+ "</td>" +
                    " <td>" + zhi.ip + "</td> " +
                    "<td>" + zhi.introduce + "</td> " +
                    "<td>" + zhi.price + "</td> " +
                    "<td>" + zhi.room_name + "</td> " +
                    "</tr>");
            });
        })

        $.post("users", {action: "count"}, function (data) {
            let json = $.parseJSON(data);
            let number = parseInt(json);

            $("#zong").append(number+"页");
            $("#dang").append(page+"页");
            $("#oo").append("<a href='zuoye.jsp?page=" + (page-1) + "&size=3'>上一页</a>");
            for (let i = 0; i < number ; i++) {
                $("#oo").append("<a href='zuoye.jsp?page=" + (i+1) + "&size=3'>" + (i + 1) + "</a>&nbsp;&nbsp;&nbsp;&nbsp;");
            }
            $("#oo").append("<a href='zuoye.jsp?page=" + (page+1) + "&size=3'>下一页</a>");
        });

    });
</script>
<body>

<div>
    <table border="1px soild " id="tab">
        <tr>
            <th>id</th>
            <th>酒店名称  </th>
            <th>位置</th>
            <th>介绍</th>
            <th>价格</th>
            <th>房间名称 </th>
        </tr>

    </table>
    <div style="border: 1px solid ;width: 300px" id="oo"><span id="zong">总共:</span><span id="dang">当前页:</span></div>
</div>
</body>
</html>
